<template>
<transition name="slider">
  <!--<div class="singer-detail" style="position:fixed; z-index: 100; top: 0; left: 0; right:0; bottom: 0; background:#333;  ">ksdfjkdsfdsjfds</div>-->
<music-list :songs = songs :bg-image="bgImage" :title = "title"  ></music-list>
</transition>
</template>

<script type="text/ecmascript-6">
import { mapGetters } from 'vuex'
import { getSingerDetail } from '../../api/singer'
import { createSong } from '../../common/js/song'
import MusicList from '../../components/music-list/music-list.vue'

export default {
  data () {
    return {
      songs: []
    }
  },
  computed: {
    title () {
      return this.singer.singer_name
    },
    bgImage () {
      return this.singer.singer_pic
    },
    ...mapGetters([
      'singer'
    ])
  },
  created () {
    this._getSingerDetail()
  },
  methods: {
    _getSingerDetail () {
      if (!this.singer.singer_mid) {
        this.$router.push('/singer')
      }

      getSingerDetail(this.singer.singer_mid, (res) => {
        const musicList = res.data.singer.data.songlist
        this.songs = this._normalizeSongs(musicList)
      })
    },
    _normalizeSongs (list) {
      let ret = []
      list.forEach((item) => {
        if (item.id && item.index_album) {
          ret.push(createSong(item))
        }
      })
      return ret
    }
  },
  components: {
    MusicList
  }
}
</script>

<style scoped lang="stylus" rel="stylesheet/stylus">
  @import "../../common/stylus/variable.styl";
  .slide-enter-active, .slide-leave-active
    transition: all 0.3s

  .slide-enter, .slide-leave-to
    transform: translate3d(100%, 0, 0)
</style>